package com.ly.web.controller.erp;

import com.ly.common.utils.StringUtils;
import com.ly.heart.service.IContractProjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ly.common.annotation.Log;
import com.ly.common.core.controller.BaseController;
import com.ly.common.core.domain.AjaxResult;
import com.ly.common.enums.BusinessType;
import com.ly.heart.domain.ContractProjectEntity;

import javax.annotation.Resource;

/**
 * 合同信息;1:EPC;2:EMC;3:分包;Controller
 * @author wutao
 * @date 2024-05-31
 */
@Api (value = "ContractProject", tags = "合同信息;1:EPC;2:EMC;3:分包;")
@RestController
@RequestMapping ("/heart/ContractProject")
public class ContractProjectController extends BaseController {

    @Resource
    private IContractProjectService contractProjectEntityService;

    /**
     * 查询合同信息;1:EPC;2:EMC;3:分包;列表
     */
    @PreAuthorize ("@ss.hasPermi('heart:ContractProject:list')")
    @GetMapping ("/list")
    @ApiOperation ("查询合同信息;1:EPC;2:EMC;3:分包;列表")
    public AjaxResult list (ContractProjectEntity contractProjectEntity) {
        AjaxResult ajaxResult = contractProjectEntityService.selectContractProjectEntityList ( contractProjectEntity );
        return ajaxResult;
    }

    /**
     * 获取合同信息;1:EPC;2:EMC;3:分包;详细信息
     */
    @PreAuthorize ("@ss.hasPermi('heart:ContractProject:query')")
    @GetMapping (value = "/{id}")
    @ApiOperation ("获取合同信息;1:EPC;2:EMC;3:分包;详细信息")
    public AjaxResult getInfo (@PathVariable ("id") String id) {
        return AjaxResult.success ( contractProjectEntityService.selectContractProjectEntityById ( id ) );
    }

    /**
     * 新增合同信息;1:EPC;2:EMC;3:分包;
     */
    @PreAuthorize ("@ss.hasPermi('heart:ContractProject:add')")
    @Log (title = "合同信息;1:EPC;2:EMC;3:分包;", businessType = BusinessType.INSERT)
    @PostMapping ("draft")
    @ApiOperation ("新增合同信息;1:EPC;2:EMC;3:分包;")
    public AjaxResult draft (@RequestBody ContractProjectEntity contractProjectEntity) {
        if ( StringUtils.isBlank ( contractProjectEntity.getId () ) ) {
            return contractProjectEntityService.draft ( contractProjectEntity );
        }
        return contractProjectEntityService.updateContractProjectEntity ( contractProjectEntity );
    }

    @PreAuthorize ("@ss.hasPermi('heart:ContractProject:add')")
    @Log (title = "合同信息;1:EPC;2:EMC;3:分包;", businessType = BusinessType.INSERT)
    @PostMapping ("submit")
    @ApiOperation ("新增合同信息;1:EPC;2:EMC;3:分包;")
    public AjaxResult submit (@RequestBody ContractProjectEntity contractProjectEntity) {
        return contractProjectEntityService.submit ( contractProjectEntity );
    }

    /**
     * 修改合同信息;1:EPC;2:EMC;3:分包;
     */
    @PreAuthorize ("@ss.hasPermi('heart:ContractProject:edit')")
    @Log (title = "合同信息;1:EPC;2:EMC;3:分包;", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation ("修改合同信息;1:EPC;2:EMC;3:分包;")
    public AjaxResult edit (@RequestBody ContractProjectEntity contractProjectEntity) {
        return contractProjectEntityService.updateContractProjectEntity ( contractProjectEntity );
    }

    /**
     * 删除合同信息;1:EPC;2:EMC;3:分包;
     */
    @PreAuthorize ("@ss.hasPermi('heart:ContractProject:remove')")
    @Log (title = "合同信息;1:EPC;2:EMC;3:分包;", businessType = BusinessType.DELETE)
    @DeleteMapping ("/{ids}")
    @ApiOperation ("删除合同信息;1:EPC;2:EMC;3:分包;")
    public AjaxResult remove (@PathVariable String[] ids) {
        return toAjax ( contractProjectEntityService.deleteContractProjectEntityByIds ( ids ) );
    }
}
